<?php
#autor Marek Křivan
# (c) 2009 

        if(isset($_POST['neodeslat_form'])) {
                echo "<meta http-equiv=\"refresh\" content=\"1;index.php?p=components&name=forum&a=ban_ip\" />";
                exit();
        } elseif(isset($_POST['odbanovat'])) {
                $query = $GLOBALS['db']->query("DELETE FROM " . $GLOBALS['db_prefix'] ."forum_ip_ban WHERE id = '".$_POST['ip_id']."' LIMIT 1;");
                $log->write(8, 'com_forum', 'NOW()', 'User delete BAN #'.$_POST['ip_id'], $_SESSION['id']);
                echo "<meta http-equiv=\"refresh\" content=\"1;index.php?p=components&name=forum&a=ban_ip\" />";
                exit();
        } elseif(isset($_POST['zabanovat'])) {
                $query = $GLOBALS['db']->query("INSERT INTO " . $GLOBALS['db_prefix'] ."forum_ip_ban SET ip = '".$_POST['ip']."';");
                $log->write(8, 'com_forum', 'NOW()', 'User added BAN to IP '.$_POST['ip'], $_SESSION['id']);
                echo "<meta http-equiv=\"refresh\" content=\"1;index.php?p=components&name=forum&a=ban_ip\" />";
                exit();
        }


?>
        <br> <h3><b>Zabanované IP adresy</b></h3>
<?php 
        if(isset($_GET['ban'])) { 
?>
        <form action="/administrator/index.php?p=components&name=forum&a=ban_ip" method="post">
                <fieldset>
                        <legend>Zabanování IP adresy</legend>
                        <label>Opravdu si přejete zabanovat IP adresu <b><?php echo $_GET['ban']; ?></b>?</label>
                        <input type="hidden" name="ip" value="<?php echo $_GET['ban']; ?>" />
                        <input type="submit" value="Ano" name="zabanovat" />
                        <input type="submit" value="Ne" name="neodeslat_form" /><br /><br />
                </fieldset>
        </form>
        <div id="obsah">
<?php
        } elseif(isset($_GET[smazat])) {
?>
        <form action="/administrator/index.php?p=components&name=forum&a=ban_ip" method="post">
                <fieldset>
                        <legend>Odbanování IP adresy</legend>
                        <label>Opravdu si přejete zrušit ban této IP adresy?</label>
                        <input type="hidden" name="ip_id" value="<?php echo $_GET['smazat']; ?>" />
                        <input type="submit" value="Ano" name="odbanovat" />
                        <input type="submit" value="Ne" name="neodeslat_form" /><br /><br />
                </fieldset>
        </form>
        <div id="obsah"> 
<?php
        } else { echo "<div id=\"obsah\">Pro zabanování IP adresy přejděte na příslušný příspěvek ve fóru a klikněte na odkaz <em>IP adresa</em>.<br /><br />"; }
?>
                <table class="ip_ban" cellspacing="0" cellpadding="0">
                        <tr class="ip_ban_hlavicka">
                                <td align="center">IP adresa</td>
                                <td align="center">zrušit BAN</td>
                        </tr>
<?php
        if(empty($_GET['strana'])) { $strana = 1; } else { $strana = 1 * $_GET['strana']; }
        $od = ($strana - 1) * 20;
        $query = $GLOBALS['db']->query("SELECT * FROM " . $GLOBALS['db_prefix'] ."forum_ip_ban ORDER BY ip LIMIT $od,20;");
        $i = 0;
        while ($row = $query->fetch_array()) {
                if($i % 2) { $tr = " class=\"tr_2\""; } else { $tr = ""; }
                echo "\t\t\t<tr".$tr.">\n\t\t\t\t<td>".$row[ip]."</td><td align=\"center\"><a href=\"/administrator/index.php?p=components&name=forum&a=ban_ip&smazat=".$row[id]."\" title=\"Smazat\">zrušit</a></td>\n\t\t\t</tr>\n";
                $i++;
        }

        if($i == 0) { echo "<tr><td colspan=\"2\" align=\"center\"><em>prázdné</em></td></tr>"; }

        echo "\t\t\t<tr>\n\t\t\t\t<td colspan=\"2\"><div id=\"strankovani_ip\">Strana:&nbsp;";

        $query = $GLOBALS['db']->query("SELECT count(*) FROM " . $GLOBALS['db_prefix'] ."forum_ip_ban;");
        while ($row = $query->fetch_array()) {
        $pocet_prispevku = $row[0];
        $stran = ceil($pocet_prispevku / 20);
        for($i = 1; $i <= $stran; $i++) {
                echo "<a href=\"/administrator/index.php?p=components&name=forum&a=ban_ip&strana=".$i."\" title=\"Ban IP\">";
                if($strana == $i) { echo "<b>".$i."</b>"; } else { echo $i;} 
                if($i != $stran) { echo "</a>&nbsp;.&nbsp;"; } else { echo "</a>&nbsp;"; }
        }
        }

?></table>